package edu.scau.web.sku;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.core.constants.AjaxResult;
import edu.scau.core.constants.HttpStatus;
import edu.scau.pos.vo.OrdersVo;
import edu.scau.sku.domain.SkuRecord;
import edu.scau.sku.service.SkuRecordService;
import edu.scau.sku.vo.SkuColorSizeVo;
import edu.scau.sku.vo.SkuRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/skuRecord")
@Tag(name = "库存记录接口")
public class SkuRecordController {
    @Autowired
    private SkuRecordService skuRecordService;
    @Operation(
            summary = "查找所有出入库记录",
            description = "查找所有出入库记录,访问权限:admin、IM",
            parameters = {
                    @Parameter(name = "pageNum", description = "页码", required = true, schema = @Schema(type = "int")),
                    @Parameter(name = "pageSize", description = "每页数据条数", required = true, schema = @Schema(type = "int")),
            },
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SkuRecordVo.class))),
                    @ApiResponse(responseCode = "400", description = "错误", content = @Content(mediaType = "application/json", schema = @Schema(implementation = HttpStatus.class)))
            }
    )
    @PreAuthorize("hasAnyAuthority('admin','IM')")
    @GetMapping("/listAll")
    public AjaxResult listAll(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize
    ) {
        PageHelper.startPage(pageNum, pageSize);
        List<SkuRecordVo> skuRecordVoList = skuRecordService.listAll();
        PageInfo<SkuRecordVo> pageInfo = new PageInfo<>(skuRecordVoList);
        return AjaxResult.success(pageInfo);
    }
}
